import itertools
import os
import logging

from loguru import logger as log

from app.core.logs import InterceptHandler

# [ System information ]
API_PREFIX = "/api"
VERSION = "1.0.0"
PROJECT_NAME = "Vista-Glimpse"
DEBUG = True

# [ Project directory ]
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# [ Log information ]
LOG_LEVEL = "INFO"
LOG_FORMAT = '{time:YYYY-MM-DD at HH:mm:ss} {level} {message}'
LOG_FILENAME = "ffms.log"
LOG_PATH = os.path.join(os.path.join(BASE_DIR, "logs"), LOG_FILENAME)
LOGGERS = ("uvicorn.asgi", "uvicorn.access")

logging.getLogger().handlers = [InterceptHandler()]
for logger_name in LOGGERS:
    logging_logger = logging.getLogger(logger_name)
    logging_logger.handlers = [InterceptHandler(level=LOG_LEVEL)]

log.add(
    LOG_PATH,
    rotation="50MB",
    encoding="utf-8",
    format=LOG_FORMAT,
    level=LOG_LEVEL,
    enqueue=True,
    retention="10 days",
)

# [ Development ]
RESOURCE_PATH = os.path.join(BASE_DIR, "resource")

# [ Produce ]
# PROD_RESOURCE_PATH = "/opt/resource"

# [ System support file types ]

SUPPORT_FILES = {
    "video":[".mp4", ".ogg"],
    "images":[".png", ".jpg"],
    "excel":[".xls", ".xlsx"],
}

for item in SUPPORT_FILES:
    _path = os.path.join(RESOURCE_PATH, item)
    if not os.path.exists(_path):
        os.chdir(RESOURCE_PATH)
        os.mkdir(item)



# [ Cors ]
CORS_ORIGINS = ["*"]
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_METHODS = ["*"]
CORS_ALLOW_HEADERS = ["*"]
